﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<ul class="vertical_menu">
<% foreach (var item in System.Web.HttpRuntime.Cache["MenuItemsSub"] as IEnumerable<ProjectFitus.Models.MenuItem>)
    {
        //******************************************************************************
        //lógík byrjar til að setja css class á selected menuItem
        var selAttribute = new { @class = "not-selected" }; //redding, ekki hægt að lýsa henni yfir með null :(
        if (ViewContext.RouteData.Values["controller"].ToString() == item.controllerName
            && ViewContext.RouteData.Values["action"].ToString() == item.actionName)
        {
            if (!String.IsNullOrEmpty(item.routeValues))
            {
                if (ViewContext.RouteData.Values["id"].ToString() == item.routeValues)
                {
                    selAttribute = new { @class = "menu-selected" };
                }
            }
            else
            {
                selAttribute = new { @class = "menu-selected" };
            }
        }//if setning endar fyrir css class lógík
                   
        //******************************************************
        // Hér fyrir neðan er svo lógík til að birta MenuItems samkvæmt réttindum notanda
        if ((item.userRole != "public" && Request.IsAuthenticated) && (Page.User.IsInRole(item.userRole.Trim())))
        {
        %>
            <li>
                <%= Html.ActionLink(
                    item.linkName,
                    item.actionName,
                    item.controllerName,
                    new { id = item.routeValues },
                    selAttribute
                    ) 
                %>
            </li>
    <% }
        
       if (item.userRole.Trim().ToLower() == "public")
       {
       %>
            <li>
                <%= Html.ActionLink(
                    item.linkName,
                    item.actionName,
                    item.controllerName,
                    new { id = item.routeValues },
                    selAttribute
                    ) 
                %>
            </li>
    <% }
    }
    %>
</ul>
<br style="clear:left;" />
